// UVa1279 Asteroid Rangers
// 刘汝佳
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

const int maxn = 50 + 5, maxks = maxn * (maxn + 1) / 2;
const double eps = 1e-8;

struct Event {
  double t;
  int newks, oldks;  //每个事件后, newks比oldks小
  Event(double t = 0, int newks = 0, int oldks = 0)
    : t(t), newks(newks), oldks(oldks) {}
  bool operator<(const Event& rhs) const { return t - rhs.t < 0; }
};
int n, nks;
vector<Event> ES;

struct KineticPoint {
  double x, y, z;     //初始位置
  double dx, dy, dz;  //初始速度
  void read() { scanf("%lf%lf%lf%lf%lf%lf", &x, &y, &z, &dx, &dy, &dz); }
} kp[maxn];

struct KineticSegment {
  double a, b, c;                                    //长度是at^2+bt+c
  int u, v;                                          //端点
  bool operator<(const KineticSegment& rhs) const {  //初始长度比较
    return c - rhs.c < 0;
  }
} ks[maxks];

inline double sqr(double x) { return x * x; }

// union-find
int pa[maxn];

void init_ufset() {
  for (int i = 0; i < n; i++) pa[i] = i;
}
int findset(int x) { return pa[x] != x ? pa[x] = findset(pa[x]) : x; }

void make_segments() {
  nks = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      /*
        点i和点j的距离平方是 sum{((kp[i].dx-kp[j].dx)*t+ (kp[i].x- kp[j].x)) ^2}
        可以写成 at^2 + bt + c. a > 0, c > 0
      */
      ks[nks].a = sqr(kp[i].dx - kp[j].dx) + sqr(kp[i].dy - kp[j].dy) +
                  sqr(kp[i].dz - kp[j].dz);
      ks[nks].b = 2 * ((kp[i].dx - kp[j].dx) * (kp[i].x - kp[j].x) +
                       (kp[i].dy - kp[j].dy) * (kp[i].y - kp[j].y) +
                       (kp[i].dz - kp[j].dz) * (kp[i].z - kp[j].z));
      ks[nks].c = sqr(kp[i].x - kp[j].x) + sqr(kp[i].y - kp[j].y) +
                  sqr(kp[i].z - kp[j].z);
      ks[nks].u = i;
      ks[nks].v = j;
      nks++;
    }
  sort(ks, ks + nks);
}

void make_events() {
  ES.clear();
  for (int i = 0; i < nks; i++)
    for (int j = i + 1; j < nks; j++) {
      int s1 = i, s2 = j; //  //何时线段i和j长度相等?
      if (ks[s1].a - ks[s2].a < 0)
        s1 = j, s2 = i;  // s1更陡

      double a = ks[s1].a - ks[s2].a;
      double b = ks[s1].b - ks[s2].b;
      double c = ks[s1].c - ks[s2].c;
      if (fabs(a) < eps) {            // bt + c = 0
        if (fabs(b) < eps) continue;  // 无解
        if (b > 0) {
          swap(s1, s2);
          b = -b;
          c = -c;
        }                                                // bt + c = 0, b < 0
        if (c > 0) ES.push_back(Event(-c / b, s1, s2));  // t > 0
        continue;
      }
      double delta = b * b - 4 * a * c;
      if (delta < eps) continue;  // no solution
      delta = sqrt(delta);
      double t1 = -(b + delta) / (2 * a);           // 答案 1
      double t2 = (delta - b) / (2 * a);            // 答案 2
      if (t1 > 0) ES.push_back(Event(t1, s1, s2));  // 更陡的更小
      if (t2 > 0) ES.push_back(Event(t2, s2, s1));  // 更平的更小
    }
  sort(ES.begin(), ES.end());
}

int solve() {
  int pos[maxks];  // pos[i]：线段i在MST中的编号，0表示不在MST中
  int e[maxn];  // e[i]是MST中的第i条边，pos[e[i]] = i
  init_ufset(); //计算初始的MST
  for (int i = 0; i < nks; i++) pos[i] = 0;
  int idx = 0;
  for (int i = 0; i < nks; i++) {
    int u = findset(ks[i].u), v = findset(ks[i].v);
    if (u != v) {
      e[pos[i] = ++idx] = i;
      pa[u] = v;
    }
    if (idx == n - 1) break;
  }

  int ans = 1;
  for (int i = 0; i < ES.size(); i++) {
    if (pos[ES[i].oldks] && (!pos[ES[i].newks])) {
      init_ufset();
      int oldpos = pos[ES[i].oldks];
      for (int j = 1; j < n; j++)
        if (j != oldpos) {
          int u = findset(ks[e[j]].u), v = findset(ks[e[j]].v);
          if (u != v) pa[u] = v;
        }
      int u = findset(ks[ES[i].newks].u), v = findset(ks[ES[i].newks].v);
      if (u != v) {  //新的MST用newks替换oldks
        ans++;
        pos[ES[i].newks] = oldpos, e[oldpos] = ES[i].newks, pos[ES[i].oldks] = 0;
      }
    }
  }
  return ans;
}

int main() {
  for (int kase = 1; scanf("%d", &n) == 1; kase++) {
    for (int i = 0; i < n; i++) kp[i].read();
    make_segments(), make_events();
    int ans = solve();
    printf("Case %d: %d\n", kase, ans);
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》例题11-14
*/
// Accepted 660ms 4536 C++5.3.0 2020-12-14 18:08:26 25846697